import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'

Vue.use(Vuex)

const actions = {
	jiaOdd(miniStore,value){
		if(miniStore.state.sum % 2){
			miniStore.commit('JIA',value)
		}
	},
	jiaWait(miniStore,value){
		setTimeout(() => {
			miniStore.commit('JIA',value)
		},500)
	},
	jiaServer(ministore){
		axios.get('https://api.uixsj.cn/hitokoto/get?type=soup').then(
			response => {
				console.log(response.data)
				ministore.commit('JIA',response.data.length)
			},
			error => {
				alert(error)
			}
		)
	}
}

const mutations = {
	JIA(state,value){
		state.sum += value
	},
	JIAN(state,value){
		state.sum -= value
	}
}

const state = {
	sum:0 
}

export default new Vuex.Store({
	actions,
	mutations,
	state
})